Skip to content

Upload working version#1

Merged
ArtyomGaribyan merged 1 commit intomainfrom
first-iteration
Nov 23, 2025
Merged

Upload working version#1
ArtyomGaribyan merged 1 commit intomainfrom
first-iteration

Conversation

@ArtyomGaribyan
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@ivannizh ivannizh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет! Хорошая работа, но нужно еще над ней немного поработать, чтобы ее можно было зачесть.

Comment thread README.md
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хороший ридми

Comment thread main.go
)

func main() {
go func() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это плохой патерн, тут у нас идет все по очереди: проинициализоровать БД, потом запустить сервер, а так подход дает асинхронность, которая тут и не нужна

Comment thread main.go
func main() {
go func() {
err := db.InitDB()
if err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

После проверки на ошибки нужно закрыть БД через defer

Comment thread pkg/api/addtask.go
"github.com/ArtyomGaribyan/Task-Scheduler/pkg/db"
)

func checkTask (task *db.Task) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень понятно зачем тут ссылка, Task - маленькая структура, которую проще скопировать, чем по ссылке передавать

Comment thread pkg/api/addtask.go
} else {
_, err := time.Parse(db.DateLayout, task.Date)
if err != nil {
return fmt.Errorf("invalid date format: %v", err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При оборачивании нужно использовать %w (wrap), а просто при выводе в консоль %v

Suggested change
return fmt.Errorf("invalid date format: %v", err)
return fmt.Errorf("invalid date format: %w", err)

Comment thread pkg/api/task.go

func HandleTasks(w http.ResponseWriter, r *http.Request) {
tasks, err := db.Tasks(50)
if err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Теряешь сообщение с ошибкой, сложно будет дебажить ошибки.
Можно просто вывести в лог.

Comment thread pkg/api/task.go
})
}

func UpdateTaskHandler(task *db.Task) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этих функциях такие же проблемы

  1. Не очень понятно зачем задача по ссылке
  2. Операции с разными кодами возврата для клиента

Comment thread pkg/db/nextdate.go

days, err := strconv.Atoi(repeatSplitted[1])
if err != nil {
return time.Time{}, fmt.Errorf("invalid date format: %v", err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При оборачивании нужно использовать %w (wrap), а просто при выводе в консоль %v

Suggested change
return time.Time{}, fmt.Errorf("invalid date format: %v", err)
return time.Time{}, fmt.Errorf("invalid date format: %w", err)

Comment thread pkg/db/task.go

func AddTask(task *Task) (int64, error) {
var id int64
db, err := sql.Open(tests.SQL, tests.DBFile)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя открывается коннект к базе при каждом вызове функции, это не очень хорошо.
Нужно 1 раз создать коннект при старте программы и использовать его для всех запросов.

Comment thread pkg/db/task.go
return []*Task{}, err
}
tasks = append(tasks, &task)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

После цикла нужно проверить курсор на наличие ошибок

http://go-database-sql.org/retrieving.html

@ArtyomGaribyan ArtyomGaribyan merged commit 26bcdee into main Nov 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants